#include "NetDiskMain.h"
#include "ui_NetDiskMain.h"
#include <QDebug>
#include "MainWindow.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QUrl>

NetDiskMain::NetDiskMain(QWidget *parent) :
    QHttpRespEventHandlerWindow(parent),
    ui(new Ui::NetDiskMain){
    ui->setupUi(this);

    QNetworkRequest request;
    request.setUrl(QUrl("http://127.0.0.1:8080/contactserver/contact_list.cs?delay=4000"));
    QNetworkAccessManager* manager=new QNetworkAccessManager(this);
    this->connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(handleOriginRespSucceedEvent(QNetworkReply*)));
    QNetworkReply *reply=manager->get(request);
    this->connect(reply,SIGNAL(aboutToClose()),this,SLOT(r_aboutToClose()));
    this->connect(reply,SIGNAL(bytesWritten(qint64)),this,SLOT(r_bytesWritten()));
    this->connect(reply,SIGNAL(destroyed()),this,SLOT(r_destroyed()));
    this->connect(reply,SIGNAL(destroyed(QObject*)),this,SLOT(r_destroyed()));
    this->connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(r_downloadProgress()));
    this->connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(handleOriginRespErrorEvent(QNetworkReply::NetworkError)));
    this->connect(reply,SIGNAL(finished()),this,SLOT(r_finished()));
    this->connect(reply,SIGNAL(metaDataChanged()),this,SLOT(r_metaDataChanged()));
    this->connect(reply,SIGNAL(readChannelFinished()),this,SLOT(r_readyRead()));
    this->connect(reply,SIGNAL(readyRead()),this,SLOT(r_readyRead()));
    this->connect(reply,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(r_sslErrors()));
    this->connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,SLOT(r_uploadProgress()));
}

NetDiskMain::~NetDiskMain(){
    delete ui;
}

void NetDiskMain::handleRespSucceedEvent(QNetworkReply *reply, int eventId){
    qDebug()<<"handleRespSucceedEvent";
}

void NetDiskMain::handleRespErrorEvent(QNetworkReply::NetworkError error, int eventId){
    qDebug()<<"handleRespErrorEvent";
}

void NetDiskMain::closeEvent(QCloseEvent *){
    (dynamic_cast<MainWindow*>(parent()))->deleteWindow(this);
}

void NetDiskMain::r_aboutToClose(){
    qDebug()<<"aboutToClose";
}

void NetDiskMain::r_bytesWritten(){
    qDebug()<<"bytesWritten";
}

void NetDiskMain::r_destroyed(){
    qDebug()<<"destroyed";
}

void NetDiskMain::r_downloadProgress(){
    qDebug()<<"downloadProgress";
}

void NetDiskMain::r_error(){
    qDebug()<<"error";
}

void NetDiskMain::r_finished(){
    qDebug()<<"finished";
}

void NetDiskMain::r_metaDataChanged(){
    qDebug()<<"metaDataChanged";
}

void NetDiskMain::r_readChannelFinished(){
    qDebug()<<"readChannelFinished";
}

void NetDiskMain::r_readyRead(){
    qDebug()<<"readyRead";
}

void NetDiskMain::r_sslErrors(){
    qDebug()<<"sslErrors";
}

void NetDiskMain::r_uploadProgress(){
    qDebug()<<"uploadProgress";
}
